<template>
  <div class="contents">
    <van-overlay :show="show" class-name="bgcolor" @click="show=false">
        <div class="wrapper" @click.stop>
          <div class="block" />
        </div>
      </van-overlay>
    <nav>
      <div class="topnav clearfix">
        <router-link :to="{ name: 'present', query: { id:`${myid}` } }">
          <span class="leftlogo"></span
        ></router-link>
        <p>{{mytitle}}</p>
        <span class="rightwrod">第{{myord}}话</span>
      </div>
    </nav>
    <section>
      <ul>
        <li >
          <img v-for="(item, index) in myurl" :key="index" :src="[item.url + '?token=' + item.token]" alt="" />
        </li>
      </ul>
    </section>
  </div>
</template>

<script>
import { get } from "@/http/request";
export default {
  name: "contents",
  data() {
    return {
      myurl: {},
      mytitle:{},
      myord:{},
      myid:'27915',
      show:true,
    };
  },
  methods: {
    async initPlay(data) {
      await get("https://apis.netstart.cn/mbcomic/GetImageIndex", data).then(
        (res) => {
          console.log(res);
          let str=''
          res.data.images.forEach((item) => {
            str+= '"'+item.path+'"'+','
          });
          str=str.slice(0,-1);
          str = "["+str+"]"
        
        //   console.log(str);
            this.montagePlay({urls:str});
        }
      );
    },
    async montagePlay(data) {
      // console.log(data);
      await get("https://apis.netstart.cn/mbcomic/ImageToken", data).then(
        (res) => {
        //   console.log(res);
          this.myurl = res.data;
        }
      );
    },
  },
  created() {
    let id = this.$route.query.id;
    this.myid = this.$route.query.tilid;
    this.mytitle = this.$route.query.title;
    this.myord = this.$route.query.num;
    this.initPlay({ ep_id: id });
  },
  watch: {
    myurl(newimg, oldimg) {
      if (oldimg == null) {
        this.show = true;
      } else if (newimg) {
        this.show = false;
      }
    },
  },
};
</script>

<style lang="scss">
  .bgcolor{
  background-color: #fcfbfb;
  z-index: 1000;
}
.wrapper {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  .block {
    width: 120px;
    height: 120px;
    background-image: url(../../assets/1441607667576727.gif);
    background-size: cover;
    background-position-x: center;
    background-color: #fff;
  }
}
nav {
  position: fixed;
  top: 0;
  left: 0;
  background-color: rgba(0, 0, 0, 0.9);
  padding-left: 10px;
  width: 100%;
  height: 46px;
  color: #fff;
  // border-bottom: 1px solid #ccc;
  box-sizing: border-box;
  z-index: 100;
  .topnav {
    width: 100%;
    height: 46px;
    line-height: 46px;
    position: relative;
    text-align: left;
    .leftlogo {
      position: absolute;
      top: 15px;
      left: 5px;
      display: block;
      width: 12px;
      height: 12px;
      border-left: 3px solid #fff;
      border-top: 3px solid #fff;
      transform: rotate(-45deg);
    }
    p {
      float: left;
      font-size: 16px;
      padding-left: 30px;
    }
    .rightwrod {
      margin-left: 15px;
      font-size: 12px;
      vertical-align: middle;
    }
  }
  a,
  a:hover,
  a:focus {
    -webkit-tap-highlight-color: transparent;
  }
}
section {
  width: 100%;
  //   background-color: rgba(0, 0, 0, 0.8);
  ul {
    width: 100%;
    height: auto;
    
    li {
      width: 100%;
      padding: 0;
      display: flex;
    flex-flow: column;
    flex-direction: column;
      img {
        width: 100%;
        // object-fit: cover;
      }
    }
  }
}
</style>